<template>
    <component v-bind="$attrs" ref="components" v-if="show && customUrl != undefined" :is="customUrl"/>
</template>
<script>
import {error} from "@/utils/msg";

export default {
  name: 'olComponent',
  data() {
    return {
      customUrl: undefined,
      show: false,
    }
  },
  methods: {
    setComponent(url, method, props) {
      this.show = false;
      try {
        this.customUrl = require(`@/${url}`).default
        this.$nextTick(() => {
          this.show = true;
          if (method) {
            this.$nextTick(async () => {
              this.$refs.components[method](props);
            })
          }
        })
      } catch (e) {
        error("找不到路径：" + `@/${url}`)
      }
    },
    handleClose() {
      this.show = false;
      this.customUrl = undefined;
      this.$emit('close')
    }
  },
  created() {
  }
}
</script>
